import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By

# 打开浏览器
service = Service(r'D:\Python3.14\chromedriver.exe')
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=service, options=chrome_options)   # 创建浏览器对象
# 输入访问网址
url = r"D:\PythonProjects\python基础\UI自动化测试\01\注册实例.html"
driver.get(url)
driver.minimize_window()

"""
需求：打开‘注册实例.html’页面，完成以下操作
1). 点击‘注册A页面’链接
2). 在打开的页面中，填写注册信息
"""
time.sleep(2)
# 1  获取当前窗口句柄
current_window = driver.current_window_handle
print(current_window)
# 获取所有窗口句柄
driver.find_element(By.PARTIAL_LINK_TEXT, "注册A").click()
handles = driver.window_handles
print(handles)
# 2 打开A页面后，要判断句柄是否对应,再输入信息
for i in handles:
    if i != current_window:
        # 切换
        driver.switch_to.window(i)
time.sleep(2)
driver.find_element(By.CSS_SELECTOR, "#userA").send_keys("admin")
driver.find_element(By.CSS_SELECTOR, "#passwordA").send_keys("123456")
driver.find_element(By.CSS_SELECTOR, "#telA").send_keys("13749207799")
driver.find_element(By.CSS_SELECTOR, "#emailA").send_keys("123456@qq.com")


